package com.yang.sms.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yang.sms.entity.SmsTaskDetail;
import com.yang.sms.enums.SmsTaskDetailEnum;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* @author Billyang
* @description 针对表【sms_task_detail(短信发送任务明细)】的数据库操作Mapper
* @createDate 2024-09-26 17:56:28
* @Entity org.yang.businesstool.entity.SmsTaskDetail
*/
public interface SmsTaskDetailMapper extends BaseMapper<SmsTaskDetail> {

    @Update("update sms_task_detail set status = #{toStatus.code},remark = #{remark} where id = #{id} and status = #{fromStatus.code}")
    Integer updateStatusByStatus(@Param("toStatus") SmsTaskDetailEnum.Status toStatus, @Param("remark") String remark,
                                 @Param("id") Integer id, @Param("fromStatus") SmsTaskDetailEnum.Status fromStatus);

    @Update("update sms_task_detail set content = #{content} where id = #{id}")
    Integer updateContentById(@Param("content") String content, @Param("id") Integer id);

    @Update("update sms_task_detail set status = #{toStatus.code},actual_send_time = now(),remark = #{remark} where id = #{id}")
    Integer updateSendSuccessStatus(@Param("toStatus") SmsTaskDetailEnum.Status toStatus,
                                    @Param("remark") String remark, @Param("id") Integer id);

    @Update("update sms_task_detail set status = #{toStatus.code},remark = #{remark} where id = #{id}")
    Integer updateStatusRemark(@Param("toStatus") SmsTaskDetailEnum.Status toStatus, @Param("remark") String remark,
                               @Param("id") Integer id);

    @Update("update sms_task_detail set remark = #{remark} where id = #{id}")
    Integer updateRemark(@Param("remark") String remark, @Param("id") Integer id);

    @Select("select id from sms_task_detail where status = #{status.code} and plan_send_time < now() limit #{limit}")
    List<Integer> select4PreTimeSend(@Param("status") SmsTaskDetailEnum.Status status, @Param("limit") int limit);
}




